import UIKit

/**
    B站：https://www.bilibili.com/video/BV144411C7Gg?p=35

    第35课 类/结构体
        1. 类型判断 和 处理
        2. 对象相等性比较
 */

class A {}

class B: A {
    var name: String
    init(name: String) {
        self.name = name
    }
    
    func printName() {
        print("this is B name=" + self.name)
    }
}

class C: A {
    var name: String
    init(name: String) {
        self.name = name
    }
    
    func printName() {
        print("this is C name=" + self.name)
    }
}


func getObject(param: Int) -> A {
    if (param > 10) {
        return B(name: "BBBB")
    } else {
        return C(name: "CCCC")
    }
}

//let obj = getObject(param: 16)
let obj = getObject(param: 9)
print("obj type-of=", type(of: obj))
if (obj is B) {
    let p = obj as! B
    p.printName()
} else if (obj is C) {
    let p = obj as! C
    p.printName()
}

let objClass = type(of: obj)
print("objClass=", objClass)



let aa = A()
let bb = A()
// 二进制 不可以用 ==, 应该用 ===
//Binary operator '==' cannot be applied to two 'A' operands
//print("==", aa == bb)
print("===", aa === bb)
//Binary operator '!=' cannot be applied to two 'A' operands
//print("!=", aa != bb)
print("!==", aa !== bb)


